import { CommandDialog } from '@amcax/base';
import {
  CommandFormWrapper,
  NonDialogCommandForm,
} from '@app-base/common/components/command-form';
import { ReferencePlaneType, TopoDialogProps } from '../type';
import { RJSFSchema, UiSchema } from '@rjsf/utils';
import { CommandFormFooter } from '@app-base/common/components/command-form/footer';
import { RadioButtonFields } from './radioButtonFields';

interface BasicSurfaceType extends TopoDialogProps {
  formData: { planeType: string };
  setFormData: (data) => void;
  cmdRef?: any;
}
export const SelectBasicSurfaceDialog = ({
  title,
  onClose,
  formData,
  setFormData,
  cmdRef,
}: BasicSurfaceType) => {
  const schema: RJSFSchema = {
    type: 'object',
    properties: {
      planeType: {
        enum: [
          ReferencePlaneType.XOY,
          ReferencePlaneType.XOZ,
          ReferencePlaneType.YOZ,
        ],
        default: ReferencePlaneType.XOY,
      },
    },
  };
  const uiSchema: UiSchema = {
    planeType: {
      'ui:field': RadioButtonFields,
      'ui:options': {
        options: [
          {
            value: ReferencePlaneType.XOY,
            label: 'XY平面',
          },
          {
            value: ReferencePlaneType.YOZ,
            label: 'YZ平面',
          },
          {
            value: ReferencePlaneType.XOZ,
            label: 'XZ平面',
          },
        ],
      },
    },
  };
  return (
    <CommandDialog
      title={title}
      placement='topLeft'
      onClose={onClose}>
      <NonDialogCommandForm
        schema={schema}
        extraUiSchema={uiSchema}
        formData={formData}
        showCancel={false}
        onChange={(data) => {
          setFormData(data.formData);
          cmdRef.current?.updatePlane(data.formData.planeType);
        }}
        showSubmit={false}></NonDialogCommandForm>
      <div className='description-text'>请选择一个参考面(默认XY平面)</div>
      <CommandFormWrapper>
        <CommandFormFooter
          onClose={onClose}
          cancelText='关闭'
          showSubmit={false}
        />
      </CommandFormWrapper>
    </CommandDialog>
  );
};
